home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / xfcn / spttool.cpt / Support Tools eXternals 1.2.5 / card_4707.txt < prev    next >
Text File  |  1990-11-13  |  11KB  |  296 lines

  1. -- card: 4707 from stack: in.5
  2. -- bmap block id: 4979
  3. -- flags: 0000
  4. -- background id: 3858
  5. -- name: VolumeIsLocked
  6. ----- HyperTalk script -----
  7. on hideObjects
  8.   hide cd btn "Try It!"
  9. end hideObjects
  10.  
  11. on showObjects
  12.   show cd btn "Try It!"
  13. end showObjects
  14.  
  15.  
  16. -- part 1 (button)
  17. -- low flags: 00
  18. -- high flags: A002
  19. -- rect: left=82 top=185 right=219 bottom=175
  20. -- title width / last selected line: 0
  21. -- icon id / first selected line: 0 / 0
  22. -- text alignment: 1
  23. -- font id: 0
  24. -- text size: 12
  25. -- style flags: 8192
  26. -- line height: 16
  27. -- part name: Try it!
  28. ----- HyperTalk script -----
  29. on mouseUp
  30.   global errGlobal
  31.   put VolumePath() into diskToCheck
  32.   if diskToCheck = "" then exit mouseUp
  33.   put VolumeIsLocked(diskToCheck,"noDialog:errGlobal") into lockedState
  34.   if errGlobal Γëá empty then
  35.     answer "Error:" && errGlobal
  36.     put empty into errGlobal
  37.   else
  38.     if lockedState = "True" then put "is" into verb
  39.     else put "is not" into verb
  40.     answer "The disk ΓÇ£" & diskToCheck & "ΓÇ¥" && verb && "locked"
  41.   end if
  42. end mouseUp
  43.  
  44.  
  45.  
  46. -- part contents for background part 38
  47. ----- text -----
  48. 48/50
  49.  
  50. -- part contents for background part 20
  51. ----- text -----
  52.      An XFCN which reports whether or not the specified volume is locked.
  53.  
  54.      Calling syntax : VolumeIsLocked(volName,<"noDialog:"errorGlobal>)
  55.   VOLNAME: the volume to check.  
  56.  
  57.  
  58.  
  59. -- part contents for background part 42
  60. ----- text -----
  61. { VolumeIsLocked(VolName ┬½,ΓÇ£noDialog:ΓÇ¥errorGlobal┬╗)   }
  62. { XCMD to test for a removable disk                             }
  63. {}
  64. {   brought to you by:      Anup Murarka             Eric Carlson         }
  65. {                       ALINK:  SKEPTIC           ALINK:  cyNic   }
  66. {                                   CIS:  76004,3356         }
  67. {}
  68. {               We are part of the Support Tools Development Group,     }
  69. {               Apple Computer, Inc.      }
  70. {}
  71. {               please DO NOT contack Mac DTS for support of this code!    }
  72. {}
  73. {               please DO contact the authors for support of this code!     }
  74. {}
  75. {               Send comments, bug reports, requests to any of the above   }
  76. {               E-mail addresses or to:}
  77. {}
  78. {                           (one of us)                  }
  79. {                           Apple Computer, Inc.          }
  80. {                           900 E. Hamilton, Ave.          }
  81. {                           Campbell, CA   95008      }
  82. {                           M/S 72-L                     }
  83. {}
  84. {   Copyright:   ┬⌐ 1989, 1990 by Apple Computer, Inc., all rights reserved.     }
  85. {}
  86. { written by Eric Carlson                                        }
  87. { AppleLink:  cyNic                                              }
  88. { modification history                                                                                        }
  89. {          Date                  Initials                                    Comments                                   }
  90. {          ----              ------          ------------------------------------------------------      }
  91. {       3/1/90             ec            first written                                                                       }
  92. {       3/10/90           ec            changed so reports volume as locked if "driver needs a call"}
  93. {}
  94.  
  95. unit DiskIsLocked;
  96.  
  97. interface
  98.  
  99.     uses
  100.         hyperXCmd;
  101.  
  102.     procedure MAIN (paramPtr: XCmdPtr);
  103.  
  104. implementation
  105.  
  106.     procedure reportToUser (paramPtr: XCmdPtr;
  107.                                     msgStr: str255);
  108. {}
  109. { report something back to the user.  }
  110. { the last parameter (optional) to an external may contain }
  111.  { "noDialog" or "noDialog:GlobalName".  GlobalName is the name }
  112.  { of a HyperTalk global variable into which error messages will be }
  113.  { placed.  we've decided to use this approach to avoid confusing }
  114. { an error message with a valid result being returned from an XFCN. }
  115. {}
  116.         var
  117.             tempStr: str255;
  118.     begin
  119. {check the last param to see if the user requested that}
  120. { we suppress the error dialog }
  121.         ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr);
  122.         UprString(tempStr, true);
  123.         if pos('NODIALOG', tempStr) = 0 then
  124.     { no special error handling specified, throw up a dialog and return the error message }
  125.             begin
  126.                 SendCardMessage(paramPtr, concat('answer "', msgStr, '"'));
  127.                 paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  128.             end
  129.         else if (pos(':', tempStr) > 0) then
  130.     { requested global AND noDialog so we fill in the global and return empty }
  131.             begin
  132.                 tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr));
  133.                                                         { get the name of the HC global  to fill }
  134.                 SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr));
  135.                                                         { and fill it }
  136.                 paramPtr^.returnValue := PasToZero(paramPtr, '');      { return empty }
  137.             end
  138.         else
  139.     { requested noDialog only so we return the error condition as the result }
  140.             paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  141.     end;     { procedure }
  142.  
  143.     function AskedForHelp (paramPtr: XCmdPtr;
  144.                                     syntaxMsg: Str255;
  145.                                     copyrightMsg: Str255): boolean;
  146. {   check to see if the user sent a '?' or a '!' as }
  147. { the only parameter. if so we will respond with }
  148. { the calling syntax or the copyright/version info }
  149. { for this external }
  150. {}
  151.         var
  152.             firstStr: str255;
  153.     begin
  154.         askedForHelp := false;
  155.         if paramPtr^.paramCount = 1 then
  156.             begin
  157.                 ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr);
  158.                     { what is the first param? }
  159.                 if firstStr = '?' then
  160.                     begin
  161.                         reportToUser(paramPtr, syntaxMsg);
  162.                         askedForHelp := true
  163.                     end  { asked for help }
  164.                 else if firstStr = '!' then
  165.                     begin
  166.                         reportToUser(paramPtr, copyRightMsg);
  167.                         askedForHelp := true
  168.                     end;     { asked for copyright info }
  169.             end;     { one parameter passed }
  170.     end;     { function }
  171.  
  172.     function NumberToString (paramPtr: XCmdPtr;
  173.                                     num: LONGINT): Str255;
  174. { use the toolbox call rather than HC's }
  175.         var
  176.             tempStr: str255;
  177.     begin
  178.         NumToString(num, tempStr);
  179.         NumberToString := tempStr;
  180.     end;
  181.  
  182.     procedure ReportVolError (paramPtr: XCmdPtr;
  183.                                     errorNum: integer);
  184.         var
  185.             errMsg, tempName: str255;
  186.     begin
  187.         sysbeep(40);
  188.         case errorNum of                   { what caused the problem? }
  189.             bdNamErr: 
  190.                 errMsg := 'Bad volume name.';
  191.             extFSErr: 
  192.                 errMsg := 'External file system.';
  193.             ioErr: 
  194.                 errMsg := 'I/O Error.';
  195.             nsDrvErr: 
  196.                 errMsg := 'No such drive.';
  197.             nsvErr: 
  198.                 errMsg := 'No such volume.';
  199.             paramErr: 
  200.                 errMsg := 'No default volume.';
  201.             otherwise
  202.                 errMsg := concat('unexpected error #', NumberToString(paramPtr, errorNum));
  203.         end;         { case }
  204.  
  205.         errMsg := concat('Sorry, ', errMsg);
  206.         reportToUser(paramPtr, errMsg);
  207.         { return the error message }
  208.     end;         { function }
  209.  
  210.     function validVolumeName (volumeName: str255): str255;
  211.     { a volume name must have one (and only one) colon in it, as }
  212.     { the last character }
  213.     begin
  214.         if pos(':', volumeName) = 0 then
  215.             validVolumeName := concat(volumeName, ':')
  216.         else
  217.             validVolumeName := copy(volumeName, 1, pos(':', volumeName));
  218.     end;
  219.  
  220.     function DriveLocked (aDQEPtr: DrvQElPtr): boolean;
  221. { the long proceeding each element in the drive que contains a flag     }
  222. { in bit 7 of byte 0 which = 1 if volume is locked, 0 if disk is           }
  223. { unlocked drive, and 8 if a non removable disk is in the drive (IM    }
  224. { IV-181)     }
  225. { 6:17 PM 3/1/90 ec }
  226.         var
  227.             flagsPtr: ^longint;
  228.     begin
  229. {subtract 4 from the DrvQE1Ptr to grab the long there }
  230.         flagsPtr := pointer(ord4(aDQEPtr) - 4);
  231.         DriveLocked := (BAND(BSR(flagsPtr^, 24), 1) = 1);
  232.     end;
  233.  
  234.     function DriveNumToQueElement (driveNum: integer): DrvQElPtr;
  235. { given a drive number, return a drive que pointer for that drive  }
  236. { 12:32 PM 3/1/90 ec }
  237.         var
  238.             aQueElement: DrvQElPtr;
  239.             headPtr: QHdrPtr;
  240.     begin
  241.         headPtr := GetDrvQHdr;           { grab the drive que header }
  242.         if headPtr <> nil then
  243.             begin
  244.                 aQueElement := DrvQElPtr(headPtr^.qHead);
  245.                 while (aQueElement^.dQDrive <> driveNum) and (aQueElement <> nil) do
  246.                     aQueElement := DrvQElPtr(aQueElement^.qLink);
  247.                 DriveNumToQueElement := aQueElement;
  248.             end
  249.         else
  250.             DriveNumToQueElement := nil;
  251.     end;
  252.  
  253.     procedure VolumeIsLocked (paramPtr: XCmdPtr);
  254.         var
  255.             volToCheck, tempVar: str255;
  256.             PB: HParamBlockRec;
  257.             errorCode: OSErr;
  258.     begin
  259.         if AskedForHelp(paramPtr, 'VolumeIsLocked(volumeName, ┬½ΓÇ£noDialog:ΓÇ¥errorGlobal┬╗)', '┬⌐ 1990 Apple Computer, Inc., v1.0 by Eric Carlson') then
  260.             exit(VolumeIsLocked);
  261.  
  262.         if paramPtr^.paramCount = 0 then
  263.             begin
  264.                 ReportToUser(paramPtr, 'Volume name expected.');
  265.                 exit(VolumeIsLocked);
  266.             end
  267.         else
  268.             ZeroToPas(paramPtr, paramPtr^.Params[1]^, volToCheck);
  269.         volToCheck := validVolumeName(volToCheck);                  { make sure the volume name is correct }
  270.  
  271.  
  272.     { initialize parameter block.  Since volToCheck is a full pathname, no other field is needed}
  273.         zeroBytes(paramPtr, @PB, sizeOf(PB));
  274.         PB.ioNamePtr := @volToCheck;
  275.         PB.ioVolIndex := -1;                            { use name ONLY }
  276.         errorCode := PBHGetVInfo(@PB, false);
  277.         if errorCode <> noErr then
  278.             begin
  279.                 reportVolError(paramPtr, errorCode);
  280.                 exit(VolumeIsLocked);
  281.             end;
  282.  
  283.         if DriveLocked(DriveNumToQueElement(PB.ioVDrvInfo)) then      { is it locked?? }
  284.             tempVar := 'True'
  285.         else
  286.             tempVar := 'False';
  287.         ParamPtr^.returnValue := PasToZero(paramPtr, tempVar);
  288.  
  289.     end;         { procedure VolumeIsLocked}
  290.  
  291.     procedure MAIN (paramPtr: XCmdPtr);
  292.     begin
  293.         VolumeIsLocked(paramPtr);
  294.     end;
  295.  
  296. end.     { unit DiskIsLocked}